<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 17-1-18
 * Time: 上午10:44
 */

//变量范围

//global 关键字

$a = 1;
$b = 2;

function Sum()
{
    global $a, $b;

    $b = $a + $b;
}
function Sum2(){
    $GLOBALS['b'] = $GLOBALS['a'] + $GLOBALS['b'];
}
Sum();
echo $b.PHP_EOL;//3
Sum();
echo $b.PHP_EOL;//4


//使用静态变量
function test()
{
    static $count = 0;

    $count++;
    echo $count.PHP_EOL;
    if ($count < 10) {
        test();
    }
    $count--;
}
test();
